package cn.wp.ewallet.common.dao.impl;

import cn.wp.common.core.dao.JdbcSupportTemplate;
import cn.wp.common.core.dao.SqlString;
import cn.wp.ewallet.common.dao.ConverRoleDictDao;
import cn.wp.ewallet.common.extension.constant.EwalletConstant;
import cn.wp.ewallet.common.model.entity.ConverRuleDictDo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by yangjin on 2020/1/11
 */
@Repository
public class ConverRoleDictDaoImpl implements ConverRoleDictDao {

    @Autowired
    private JdbcSupportTemplate jdbcSupportTemplate;

    @Override
    public void insertConverRuleDict(ConverRuleDictDo converRuleDictDo) {
        jdbcSupportTemplate.insert(converRuleDictDo);
    }

    @Override
    public ConverRuleDictDo selectConverRuleDict(String baseMoney, String priceMoney, String converType) {
        SqlString sqlString = SqlString.newInstance();
        sqlString.add("SELECT * FROM `conver_rule_dict` where BASE_MONEY = ? and PRICE_MONEY = ? and CONVER_TYPE = ? and `STATUS` = ?;");
        Object[] params = new Object[]{
            baseMoney,
            priceMoney,
            converType,
            EwalletConstant.STATUS
        };
        return jdbcSupportTemplate.selectObject(sqlString.build(),params,ConverRuleDictDo.class);
    }

    @Override
    public List<ConverRuleDictDo> selectConverRuleDict() {
        SqlString sqlString = SqlString.newInstance();
        sqlString.add("SELECT * FROM `conver_rule_dict` where `STATUS` = ?");
        Object[] params = new Object[]{
                EwalletConstant.STATUS
        };
        return jdbcSupportTemplate.selectList(sqlString.build(),params,ConverRuleDictDo.class);
    }

    @Override
    public void updateConverRuleDict(ConverRuleDictDo converRuleDictDo) {
        jdbcSupportTemplate.update(converRuleDictDo);
    }


}
